//app.js
var utils = require('utils/util.js');
App({
  onLaunch: function() {



  },
  makeLogin: function(callback = '', share_id = '') {
    var that = this;
    // 登录
    wx.login({
      success: res => {
        console.log(res);
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        utils.showLoading("正在登陆")
        utils.http("/api/v1/login/index_wx", {
          js_code: res.code,
          share_id: share_id
        }, (res) => {
          console.log(res);
          utils.hideLoading();
          that.globalData.key = res.datas.key;
          wx.setStorageSync('key', res.datas.key)
          if (typeof callback == 'function') {
            callback();
          }
          if (wx.getStorageSync("userType").type == 1) {
            //1  商户
            wx.reLaunch({
              url: '../business/business',
            })
          }
          if (wx.getStorageSync("userType").type == 2) {
            //2 果农
            wx.reLaunch({
              url: '../farmerend/farmerend',
            })
          }
        })
      }
    })
  },
  memberModify: function(data, callback) {
    utils.http("/api/v1/member/member_modify", data, function(res) {
      console.log(res)
      if (typeof callback == 'function') {
        callback();
      }
    })
  },
  globalData: {
    userInfo: null,
    http: "https://xinong.qidian2018.com/index.php/"
  }
})